package ar.edu.utn.frba.dds.opendesigners.format;

import java.util.Date;
import java.text.ParseException;
import java.text.ParsePosition;
import java.text.SimpleDateFormat;
import java.util.Calendar;

import ar.edu.utn.frba.dds.opendesigners.exception.BusinessException;

public class FormatDateHard implements FormatDate{
	private SimpleDateFormat format;
	
	public FormatDateHard(String stringFormat) {
		this.format = new SimpleDateFormat(stringFormat);
		this.format.setLenient(false);
	}
	
	private Date parse(String stringDate){
		try {
			return this.format.parse(stringDate);
		} catch (ParseException e) {
			throw new BusinessException("La cadena no tiene el patron correcto");
		}
		
	}
	
	@Override
	public Calendar create(String stringDate) {
		Calendar calendar =  Calendar.getInstance();
		calendar.setTime(this.parse(stringDate));
		return calendar;
	}
		
}
